package com.leessy.r229.utils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class BoardWatchUtils {
    public static final String WATCHDOG_PATH = "/dev/watchdog";
    //开启看门狗/喂狗
    public static void openWatchdog() {
        writeWatchdog(1);
    }
    //关闭看门狗
    public static void closeWatchdog() {
        writeWatchdog("V");
    }

    private static void writeWatchdog(int mode) {
        try {
            File myFile = new File(WATCHDOG_PATH);
            if (myFile.exists()) {
                FileWriter fileWriter = new FileWriter(myFile);
                fileWriter.write(String.valueOf(mode));
                fileWriter.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void writeWatchdog(String mode) {
        try {
            File myFile = new File(WATCHDOG_PATH);
            if (myFile.exists()) {
                FileWriter fileWriter = new FileWriter(myFile);
                fileWriter.write(mode);
                fileWriter.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}